package com.admin.business.background.venusOaStampApplication;

import com.tiangong.framework.annotation.OpenApi;
import com.tiangong.framework.bo.CDO;
import com.tiangong.framework.bo.Return;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @description: 用章申请表
 * @create: 2023-10-31 14:48:16
 **/
@Service("venusOaStampApplicationService")
@Slf4j
public class VenusOaStampApplicationService{

    @Resource
    VenusOaStampApplicationDao venusOaStampApplicationDao;

    /**
     * 添加用章申请表,获取id数据
     *
     * @param cdoRequest - id:主键id
     *                   - org_id:公司id
     *                   - pro_id:项目id
     *                   - user_id:申请人
     *                   - stamp_type:用章类型
     *                   - stamp_purpose:盖章用途
     *                   - stamp_position:盖章位置
     *                   - stamp_file:盖章文件
     *                   - stamp_state:状态 1:待审批 2审批中 3已同意 4已拒绝 5撤回
     *                   - stamp_user_id:盖章人
     *                   - stamp_time:盖章时间
     *                   - stamp_image:盖章图片
     *                   - stamp_red_state:红点状态 0.待查看  1.已查看
     *                   - update_time:修改时间
     *                   - begin_time:创建时间
     *                   - state:状态 0正常 1删除
     * @return
     * @author Ht
     * @create: 2023-10-31 14:48:16
     */
    @OpenApi
    public Return addVenusOaStampApplication(CDO cdoRequest) {
        venusOaStampApplicationDao.addVenusOaStampApplication(cdoRequest);
        CDO cdoResult = new CDO();
        if (cdoRequest.containsKey("id")) {
            cdoResult.set("id", cdoRequest.get("id"));
        }
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据id，更新用章申请表数据
     *
     * @param cdoRequest - id:主键id
     *                   - org_id:公司id
     *                   - pro_id:项目id
     *                   - user_id:申请人
     *                   - stamp_type:用章类型
     *                   - stamp_purpose:盖章用途
     *                   - stamp_position:盖章位置
     *                   - stamp_file:盖章文件
     *                   - stamp_state:状态 1:待审批 2审批中 3已同意 4已拒绝 5撤回
     *                   - stamp_user_id:盖章人
     *                   - stamp_time:盖章时间
     *                   - stamp_image:盖章图片
     *                   - stamp_red_state:红点状态 0.待查看  1.已查看
     *                   - update_time:修改时间
     *                   - begin_time:创建时间
     *                   - state:状态 0正常 1删除
     * @return
     * @author Ht
     * @create: 2023-10-31 14:48:16
     */
    @OpenApi
    public Return updateVenusOaStampApplicationById(CDO cdoRequest) {
        venusOaStampApplicationDao.updateVenusOaStampApplicationById(cdoRequest);
        return Return.SUCCESS;
    }

    /**
     * 根据id，删除用章申请表数据
     *
     * @param cdoRequest - id:主键id
     * @return
     * @author Ht
     * @create: 2023-10-31 14:48:16
     */
    @OpenApi
    public Return deleteVenusOaStampApplicationById(CDO cdoRequest){
        int count = venusOaStampApplicationDao.deleteVenusOaStampApplicationById(cdoRequest.getLong("id"));
        CDO cdoResult = new CDO();
        cdoResult.set("count", count);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据条件，删除用章申请表数据
     *
     * @param cdoRequest
     * @return
     * @author Ht
     * @create: 2023-10-31 14:48:16
     */
    @OpenApi
    public Return deleteVenusOaStampApplication(CDO cdoRequest) {
        int count = venusOaStampApplicationDao.deleteVenusOaStampApplication(cdoRequest);
        CDO cdoResult = new CDO();
        cdoResult.set("count", count);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据ID，获取用章申请表数据
     *
     * @param cdoRequest - id:主键id
     * @return
     * @author Ht
     * @create: 2023-10-31 14:48:16
     */
    @OpenApi
    public Return getVenusOaStampApplicationById(CDO cdoRequest) {
        CDO cdoMapperResult = venusOaStampApplicationDao.getVenusOaStampApplicationById(cdoRequest.getLong("id"));
        return Return.valueOf(cdoMapperResult);
    }

    /**
     * 根据非空条件，获取用章申请表数据列表
     *
     * @param cdoRequest
     * @return
     * @author Ht
     * @create: 2023-10-31 14:48:16
     */
    @OpenApi
    public Return getVenusOaStampApplicationListPage(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.getInteger("pageIndex")-1;
        int recordSize = 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = venusOaStampApplicationDao.getVenusOaStampApplicationListPage(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = venusOaStampApplicationDao.getVenusOaStampApplicationCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }
    /**
     * 根据混合条件，获取用章申请表数据列表
     *
     * @param cdoRequest - id:主键id
     * @return
     * @author Ht
     * @create: 2023-10-31 14:48:16
     */
    @OpenApi
    public Return getVenusOaStampApplicationListPageByCondition(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.getInteger("pageIndex")-1;
        int recordSize = 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = venusOaStampApplicationDao.getVenusOaStampApplicationListPageByCondition(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = venusOaStampApplicationDao.getVenusOaStampApplicationCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }
}
